/**
 * @ShardedJedis2ProxyFactoryBean.java  COPYRIGHT xiaojian
 * 
 * Created on 2019年7月29日 下午8:11:17
 */
package xj.toolkit.redis.shard;

import java.lang.reflect.Proxy;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.util.ClassUtils;

import com.google.common.base.Preconditions;

import xj.toolkit.redis.Jedis2Commands;

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class ShardedJedis2ProxyFactoryBean extends AbstractFactoryBean<Jedis2Commands> {
	
	private ShardedJedis2Pool jedisPool;

	public ShardedJedis2ProxyFactoryBean(ShardedJedis2Pool jedisPool) {
		Preconditions.checkArgument(jedisPool != null);
	
		this.jedisPool = jedisPool;
	}

	public Class<Jedis2Commands> getObjectType() {
		return Jedis2Commands.class;
	}

	protected Jedis2Commands createInstance() throws Exception {
		ShardedPoolInvocationHandler handler = new ShardedPoolInvocationHandler(
				jedisPool);
		return (Jedis2Commands) Proxy.newProxyInstance(
				ClassUtils.getDefaultClassLoader(),
				new Class[] { Jedis2Commands.class }, handler);
	}

}
